#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.utils;


import ${package}.common.component.service.SpringContext;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * Description: 邮件发送器
 *
 * @author wupanhua
 * @date 2019/8/6 15:28
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Slf4j
@Data
@AllArgsConstructor
public class YkMailSender implements Runnable {


    /**
     * 接受邮箱
     */
    private String email;
    /**
     * 邮件标题
     */
    private String title;
    /**
     * 邮箱信息
     */
    private String message;

    /**
     * 发送邮件的邮箱
     */
    private String sendEmail;

    /**
     * Description:
     * <邮件发送>
     * @author wupanhua
     * @date 15:58 2019/8/8
     **/
    @Override
    public void run() {
        // 获取发送邮件工具类
        JavaMailSender javaMailSender = SpringContext.getBean(JavaMailSender.class);
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,true,"UTF-8");
            //设置发件人Email
            messageHelper.setFrom(sendEmail);
            //设置邮件主题
            messageHelper.setSubject(this.title);
            String html = "<html>" +
                            "<body>" +
                            "<BR>" +
                            "<div align='left'>" +
                            "<h4>" +
                            this.message +"</br>"+
                            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
                            "<a href='http://frontend-master-itech.apps.paas.cnooc'>frontend-master-itech.apps.paas.cnooc</a>" +
                            "</h4>" +
                            "</div>" +
                            "</body>" +
                            "</html>";
            //设置邮件主题内容
            messageHelper.setText(html,true);
            messageHelper.setTo(this.email);
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            log.error("send mail error", e);
        }
    }
}
